home *** CD-ROM | disk | FTP | other *** search
- /* ASCII Transfer External for Hermes © 1990 By John Raymonds.
-
- Written in THINK C 4.0.1 as an example external for Hermes protocol
- developers. Use of any code shown below in any program other than
- an external to be used with Hermes requires written permission from
- the author:
-
- John Raymonds
- 76174,205 (Compuserve)
- D3885 (AppleLink)
-
- Comments and suggestions are welcome.
-
- */
-
- #include <:Mac #includes:SerialDvr.h>
-
- #include "Protocol.h"
- #include "ASCII.h"
-
- extern ProtoRecPtr PRP;
- extern ProtoGloPtr PGP;
-
- /* waits seconds seconds for a char on the modem port and returns it */
-
- WaitForChar(seconds)
- int seconds;
- {
- register int theChar;
- register ProtoRecPtr prp;
- register ProtoGloPtr pgp;
- register long timeouttime;
- prp = PRP;
- pgp = PGP;
- FlushWrite();
- timeouttime = TickCount() + seconds * 60;
- for (;;) {
- theChar = modemIn();
- if (prp->F.B.carrierLost) {
- /* return timeout if transfer stoped */
- return(-1);
- }
- if (theChar >= 0) {
- return(theChar);
- }
- if (TickCount() > timeouttime) {
- /* return -1 on time out */
- return(-1);
- }
- }
- }
-
- /* reads in all bytes that come in within a second of each other */
-
- FlushModemInput()
- {
- while(WaitForChar(1) != -1) {}
- }
-
- /* returns -1 if no characters are available */
-
- int modemIn()
- {
- long bytesAvail;
- register ProtoRecPtr prp;
- register ProtoGloPtr pgp;
- pgp = PGP;
- if (pgp->rbValid) {
- --pgp->rbValid;
- return((int) pgp->readBuffer[pgp->rbPos++]);
- }
- else {
- SerGetBuf(prp->mRefIn, StripAddress(&bytesAvail));
- if (bytesAvail > READBUFFSIZE) {
- bytesAvail = READBUFFSIZE;
- }
- if (bytesAvail) {
- /* read in a bunch */
- pgp->MIOPin.ioBuffer = (Ptr) StripAddress(&pgp->readBuffer);
- pgp->MIOPin.ioReqCount = bytesAvail;
- if (!prp->F.B.carrierLost) {
- PBRead(StripAddress(&pgp->MIOPin), TRUE);
- }
- do {
- if (prp->F.B.carrierLost) {
- PBKillIO(StripAddress(&pgp->MIOPin), FALSE);
- pgp->MIOPin.ioResult = 0;
- pgp->MIOPin.ioActCount = 0;
- }
- Return(prp->timeOut, &pgp->SSR);
- } while(pgp->MIOPin.ioResult == 1);
- pgp->rbValid = pgp->MIOPin.ioActCount;
- pgp->rbPos = 0;
- if (pgp->rbValid) {
- return(modemIn());
- }
- }
- else {
- Return(prp->timeOut, &pgp->SSR);
- }
- }
- return(-1);
- }
-